<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
  <style>
    td{
	   border:solid 1px black; 
	   height:30px;
	   width:100px;
	   text-align:center;
	 }
  </style>
 </head>
 <body>
    <div>
	<button id="btn_create">增加</button>
	<button id="btn_shanchu">删除</button>
	<button id="check_true">全选</button>
	<button id="check_false">全不选</button>
	</div>
	<div>
	   <table id="table">
	      <tr>
		    <td>选项</td>
			<td>内容</td>
		  </tr>
	   <table>
	</div>
 </body>
 <script>
   var btn_create = document.getElementById("btn_create");  //增加
   var btn_shanchu = document.getElementById("btn_shanchu");//删除
   var check_true = document.getElementById("check_true");  //全选
   var check_false = document.getElementById("check_false");//全不选

   //增加一行
   btn_create.addEventListener("click",function(){
      var table = document.getElementById("table");
      var tr = document.createElement("tr");
	  for(var i=0;i<2;i++){
	     td = document.createElement("td");
		 if(i==0){
		    var input = document.createElement("input");
			input.setAttribute("type","checkbox");
			input.setAttribute("class","check");
			td.appendChild(input);
		 } 
		 tr.appendChild(td);
	  }
	  table.appendChild(tr);
   })

   //删除选中的行
   btn_shanchu.addEventListener("click",function(){
      var table = document.getElementById("table");
      var TR = document.getElementsByTagName("tr");
	  var n = TR.length;
	  //alert(n);
     for(var j = 0;j < n;j++){
	     var tr = document.getElementsByTagName("tr");
		 var input = document.getElementsByClassName("check");
		 for(var i=0;i<input.length;i++){
		    if(input[i].checked == true){
		      var m = parseInt(i+1);
			 table.removeChild(tr[m]);
			 break;
		    } 
		 }
	 }
   })

   //全部选中
   check_true.addEventListener("click",function(){
     var input = document.getElementsByClassName("check");
	 for(var i=0;i<input.length;i++){
	    if(input[i].checked == false){
		   input[i].checked = true;
		}
	 }
   })

   //全不选
   check_false.addEventListener("click",function(){
      var input = document.getElementsByClassName("check");
	  for(var i=0;i<input.length;i++){
	    if(input[i].checked == true){
		  input[i].checked = false;
		}
	  }
   })
 </script>
</html>
